package com.xrui.hbase.filter;

import org.codehaus.jackson.JsonNode;

import java.util.List;

/**
 * Combines a list of row filters using a logical AND operator.
 * <p>
 * <p> Column filters are applied in order and lazily. </p>
 */
public final class AndRowFilter extends OperatorRowFilter {
    /**
     * Creates a row filter that combines a list of row filters with an AND operator.
     *
     * @param filters Row filters to combine with a logical OR.
     *                Nulls are filtered out.
     * @deprecated Use {@link Filters#and(RowFilter...)}.
     */
    @Deprecated
    public AndRowFilter(List<? extends RowFilter> filters) {
        super(OperatorRowFilter.Operator.AND, filters.toArray(new RowFilter[filters.size()]));
    }

    /**
     * Creates a row filter that combines a list of row filters with an AND operator.
     *
     * @param filters Row filters to combine with a logical AND.
     *                Nulls are filtered out.
     * @deprecated Use {@link Filters#and(RowFilter...)}.
     */
    @Deprecated
    public AndRowFilter(RowFilter... filters) {
        super(OperatorRowFilter.Operator.AND, filters);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Class<? extends RowFilterDeserializer> getDeserializerClass() {
        return AndRowFilterDeserializer.class;
    }

    /**
     * De-serializes {@code AndRowFilter}.
     */
    public static final class AndRowFilterDeserializer implements RowFilterDeserializer {
        /**
         * {@inheritDoc}
         */
        @Override
        public RowFilter createFromJson(JsonNode root) {
            final List<RowFilter> filters = OperatorRowFilter.parseFilterList(root);
            return new AndRowFilter(filters);
        }
    }
}
